import * as THREE from 'three';
// 引入轨道控制器扩展库OrbitControls.js
// import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(30, window.innerWidth / window.innerHeight, 1, 3000);
// 创建渲染器对象
const renderer = new THREE.WebGLRenderer({ antialias: true });
// class Twin {
//     constructor() {
//         initConfiguration();
//     }

// }
const initConfiguration = (mesh) => {
    // const camera = new THREE.PerspectiveCamera(30, width / height, 1, 3000);
    camera.position.set(500, 500, 500); // 将相机移得更远一些
    camera.lookAt(mesh.position);        // 让相机看向长方体

    // WebGL渲染器
    renderer.setSize(window.innerWidth, window.innerHeight);
    // 获取你屏幕对应的设备像素比.devicePixelRatio告诉threejs,以免渲染模糊问题
    renderer.setPixelRatio(window.devicePixelRatio);

    // AxesHelper：辅助观察的坐标系
    scene.add(new THREE.AxesHelper(150));

    // 自适应
    window.onresize = function () {
        // 重置渲染器输出画布canvas尺寸
        renderer.setSize(window.innerWidth, window.innerHeight);
        // 全屏情况下：设置观察范围长宽比aspect为窗口宽高比
        camera.aspect = window.innerWidth / window.innerHeight;
        // 如果相机视锥体相关参数发生了变化，需要执行updateProjectionMatrix ()方法更新相机的投影矩阵
        camera.updateProjectionMatrix();
    };
};

export{
    initConfiguration,
    THREE, scene, camera, renderer
}